package com.example.user.myzzyl_android;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;

import com.blankj.utilcode.util.FragmentUtils;

public class DengLu extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_deng_lu);
        showFragment(ZhuYeFragment.TAG, ZhuYeFragment.newInstance());
    }

    public void showFragment(String tag, Fragment fragment) {

        FragmentUtils.addFragment(getSupportFragmentManager(), fragment, R.id.FrameLayout, false, true);
    }
    private long exitTime = 0;

    @Override
    public void onBackPressed() {
        if (!(FragmentUtils.getFragments(getSupportFragmentManager()).get(0) instanceof ZhuYeFragment)) {
            super.onBackPressed();
            return;
        }
        if ((System.currentTimeMillis() - exitTime) > 2000) {
            Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
            exitTime = System.currentTimeMillis();
        } else {
            super.onDestroy();
            finish();
            System.exit(0);
        }
    }

}
